﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using WpfFeeCalculator.FeeWcfService;
using WpfFeeCalculator.Model;




namespace WpfFeeCalculator.Controllers
{
    public class ClientController : IClientController
    {
        private readonly IFeeFacade webservice;

        public ClientController(IFeeFacade phoenixFacade)
        {
            webservice = phoenixFacade;
        }

        public Task<DataResult> GetPortfolioExcel(Portfolio portfolio, DateTime date, PriceCutOff priceCutOff)
        {
            return webservice.GetPortfolioExcel(portfolio, date, priceCutOff);
        }

        public void ProcessDataResult(DataResult result, Action<string> NotifyUser, Action<System.IO.Stream> Load)
        {
            if (result == null || result.Data == null || !result.IsSuccess)
            {
                NotifyUser("No excel was returned for the given parameters. Reason:\n" +
                    ((result == null) ? string.Empty : result.Message));
                return;
            }

            var stream = new MemoryStream(result.Data);

            Load(stream);
        }

        public void ProcessDataResult(DataResult result, Action<string> NotifyUser, Action<System.IO.Stream> Load, Action PostAction)
        {
            throw new NotImplementedException();
        }
    }
}
